using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace MagicAttributeTest
{
  public partial class UCHand : UserControl
  {
    public MagicPlayer m_Player = null;
    public List<CardControl> m_GUICards = new List<CardControl>();

    public event GUIPermanentEventHandler evActivateCard;

    public UCHand()
    {
      InitializeComponent();
    }
    public void SetPlayer(MagicPlayer player)
    {
      m_Player = player;
      UpdateGUI();
    }
    public void UpdateGUI()
    {
      int size_x = 140;
      int size_y = (int)(size_x * 1.4);
      int x = 10;
      int y = 10;
      int delta_x = size_x + 10;

      foreach (CardControl cardCtrl in m_GUICards)
      {
        this.Controls.Remove(cardCtrl);
      }
      
      m_GUICards.Clear();

      foreach (Permanent permanent in m_Player.Hand)
      {
        CardControl control = new CardControl();
        control.Size = new Size(size_x, size_y);
        control.Location = new Point(x, y);
        control.SetPermanent(permanent);
        control.evActivateCard += new GUIPermanentEventHandler(control_evActivateCard);
        x += delta_x;
        m_GUICards.Add(control);
        this.Controls.Add(control);
      }
    }

    // Just forward-send the event 
    void control_evActivateCard(Permanent permanent)
    {
      if (evActivateCard != null)
        evActivateCard(permanent);
    }
  }
}
